
let stu = {
    id: 1001,
    name: '张三丰',
    gender: 'male',
    birthdate: '2001-10-20'
}

// 用 for...in 遍历对象
for (const property in stu) {
    const value = stu[ property ];
    console.log( property , value );
}

// 用 for...of 遍历对象 (失败: stu 不是可遍历对象 )
// for( let entry of stu ) {
//    console.log( entry );
// }

console.log( '- - - '.repeat( 5 ) );

let arr = ['唐三藏','孙悟空','猪悟能','沙悟净'];

// 用 for...in 遍历数组
for (const index in arr) {
    const element = arr[ index ];
    console.log( index , element );
}

// 用 for...of 遍历数组 ( 数组是可以迭代的( iterable ))
for( const element of arr ){
    console.log( element );
}


/*
let iterator = arr.values();
let x ;

do{
    x = iterator.next();
    console.log( x );
}while( !x.done );
*/